package com.atguigu.tingshu.album.client;

import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.common.cache.GuiGuCache;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.model.album.BaseCategoryView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Taeyang
 * @date 2025/4/29
 */
@RestController
@RequestMapping("/client/album/category")
public class BaseCategoryViewClientController {

    private final BaseCategoryService baseCategoryService;

    @Autowired
    public BaseCategoryViewClientController(BaseCategoryService baseCategoryService) {
        this.baseCategoryService = baseCategoryService;
    }


    /**
     * 根据专辑三级分类id从分类视图中查询专辑的分类列表
     *
     * @param category3Id
     * @return
     */
    @GuiGuCache(prefix = "getBseCategoryView:")
    @GetMapping("/getBseCategoryView/{category3Id}")
    public BaseCategoryView getBseCategoryView(@PathVariable("category3Id") Long category3Id) {
        return baseCategoryService.getBseCategoryView(category3Id);
    }

    /**
     * 根据一级分类id查询所有的二级分类和三级分类
     *
     * @param category1Id
     * @return
     */
    @GuiGuCache(prefix = "findTopBaseCategory3:")
    @GetMapping("/findTopBaseCategory3/{category1Id}")
    public List<BaseCategory3> findTopBaseCategory3(@PathVariable("category1Id") Long category1Id) {
        return baseCategoryService.findTopBaseCategory3(category1Id);
    }
}
